#ifndef _CRT_THREAD_H_
#define _CRT_THREAD_H_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

#define OS_THREAD_BUSY  100
#define OS_THREAD_ERROR 1
#define OS_THREAD_SUC   0

#if (TARGET_OS == OS_WIN)

typedef HANDLE _thread_t;
typedef DWORD _thread_id;

#elif (TARGET_OS == OS_POSIX)

typedef pthread_t _thread_t;
typedef uint64_t _thread_id;

#elif (TARGET_OS == OS_MACH)

typedef pthread_t _thread_t;
typedef uint64_t _thread_id;

#elif (TARGET_OS == OS_UNIX)

typedef pthread_t _thread_t;
typedef uint64_t _thread_id;

#endif

typedef void (*_thread_proc)(void* arg);

int _thread_create(_thread_t* tid, _thread_proc entry, void* arg);
int _thread_join(_thread_t* tid);
int _thread_equal(const _thread_t* t1, const _thread_t* t2);
_thread_id _get_cthreadid(void);
_thread_id _get_threadid(_thread_t* tid);

#ifdef __cplusplus
}
#endif

#endif
